package it.uniroma2.structure;

import java.util.Vector;

public class Receive extends Actions{
	private boolean createInstance;
	private final String defaultName = "receiveInput";
	private static int index = 1;
	private Parameter input;
	private Vector<LinkServiceNode> outLinksService;
	
	public Receive(){
		super.name = this.defaultName + Receive.index;
		Receive.index++;
		this.input = new Parameter("input", "string");
		this.outLinksService = new Vector<LinkServiceNode>();
	}
	
	public Receive(String name){
		super.name = name;
		this.input = new Parameter("input", "string");
		this.outLinksService = new Vector<LinkServiceNode>();
	}

	public boolean isCreateInstance() {
		return createInstance;
	}

	public void setCreateInstance(boolean createInstance) {
		this.createInstance = createInstance;
	}

	public String toBPEL(){
		String output = "<" + receiveTag + " " + this.toString() + "/>\n";
		for(LinkServiceNode tempLink : this.outLinksService){
			output = output + tempLink.toBPEL();
		}
		return output;
	}
	
	public Parameter getParameterInput(){
		return this.input;
	}

	@Override
	public String toString() {
		String output = "name=\"" + super.name + "\" " +
				"partnerLink=\"" + super.partnerLink.getName() + "\" " +
						"portType=\"" + super.portType + "\" " +
								"operation=\"" + super.operation + "\" " +
										"variable=\"" + super.variable.getName() + "\" ";
		if(this.createInstance){
			output = output + "createInstance=\"yes\"";
		}else{
			output = output + "createInstance=\"no\"";
		}
							
		return output;										
	}

	public void addOutLink(LinkServiceNode newLinkNode) {
		this.outLinksService.addElement(newLinkNode);
		
	}
	
	public void removeOutLink(LinkServiceNode outLink) {
		this.outLinksService.remove(outLink);
		
	}

	public LinkServiceNode getFirstLink() {
		return this.outLinksService.elementAt(0);
	}
	
	

}